<template>
  <div class="not-found-page">
    <div class="container">
      <div class="not-found-content">
        <!-- 404图标 -->
        <div class="error-icon">
          <div class="number-404">
            <span class="number">4</span>
            <span class="number zero">0</span>
            <span class="number">4</span>
          </div>
          <div class="error-illustration">
            <div class="planet">
              <div class="crater crater-1"></div>
              <div class="crater crater-2"></div>
              <div class="crater crater-3"></div>
            </div>
            <div class="astronaut">
              <div class="helmet"></div>
              <div class="body"></div>
              <div class="arm arm-left"></div>
              <div class="arm arm-right"></div>
              <div class="leg leg-left"></div>
              <div class="leg leg-right"></div>
            </div>
            <div class="stars">
              <div class="star" v-for="i in 20" :key="i" :style="getStarStyle(i)"></div>
            </div>
          </div>
        </div>

        <!-- 错误信息 -->
        <div class="error-info">
          <h1 class="error-title">页面走丢了</h1>
          <p class="error-description">
            抱歉，您访问的页面不存在或已被移动。
            <br>
            让我们帮您找到正确的方向！
          </p>
        </div>

        <!-- 操作按钮 -->
        <div class="error-actions">
          <el-button type="primary" size="large" @click="goHome">
            <el-icon><House /></el-icon>
            返回首页
          </el-button>
          <el-button size="large" @click="goBack">
            <el-icon><Back /></el-icon>
            返回上页
          </el-button>
          <el-button size="large" @click="contactSupport">
            <el-icon><Service /></el-icon>
            联系客服
          </el-button>
        </div>

        <!-- 搜索建议 -->
        <div class="search-suggestion">
          <h3 class="suggestion-title">或者试试搜索您需要的内容：</h3>
          <div class="search-box">
            <el-input
              v-model="searchQuery"
              placeholder="搜索产品、解决方案或帮助文档..."
              size="large"
              @keyup.enter="performSearch"
            >
              <template #append>
                <el-button @click="performSearch">
                  <el-icon><Search /></el-icon>
                </el-button>
              </template>
            </el-input>
          </div>
        </div>

        <!-- 热门链接 -->
        <div class="popular-links">
          <h3 class="links-title">热门页面</h3>
          <div class="links-grid">
            <div 
              class="link-item" 
              v-for="link in popularLinks" 
              :key="link.id"
              @click="navigateTo(link.path)"
            >
              <div class="link-icon">
                <el-icon><component :is="link.icon" /></el-icon>
              </div>
              <div class="link-content">
                <h4 class="link-title">{{ link.title }}</h4>
                <p class="link-description">{{ link.description }}</p>
              </div>
            </div>
          </div>
        </div>

        <!-- 帮助信息 -->
        <div class="help-info">
          <div class="help-card">
            <div class="help-icon">
              <el-icon><QuestionFilled /></el-icon>
            </div>
            <div class="help-content">
              <h4 class="help-title">需要帮助？</h4>
              <p class="help-description">
                如果您认为这是一个错误，请联系我们的技术支持团队。
                我们将尽快为您解决问题。
              </p>
              <div class="help-actions">
                <el-button text type="primary" @click="reportError">
                  报告错误
                </el-button>
                <el-button text @click="viewFAQ">
                  查看FAQ
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 背景动画 -->
    <div class="background-animation">
      <div class="floating-shapes">
        <div class="shape shape-1"></div>
        <div class="shape shape-2"></div>
        <div class="shape shape-3"></div>
        <div class="shape shape-4"></div>
        <div class="shape shape-5"></div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import {
  House,
  Back,
  Service,
  Search,
  QuestionFilled,
  Monitor,
  Setting,
  Document,
  Phone
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const router = useRouter()
const route = useRoute()
const searchQuery = ref('')

// 热门链接
const popularLinks = [
  {
    id: 1,
    title: '产品中心',
    description: '了解我们的核心产品和解决方案',
    icon: 'Monitor',
    path: '/product'
  },
  {
    id: 2,
    title: '解决方案',
    description: '查看行业解决方案和技术架构',
    icon: 'Setting',
    path: '/solutions'
  },
  {
    id: 3,
    title: '帮助文档',
    description: '获取详细的使用指南和FAQ',
    icon: 'Document',
    path: '/service'
  },
  {
    id: 4,
    title: '联系我们',
    description: '获得专业的技术支持和服务',
    icon: 'Phone',
    path: '/contact'
  }
]

// 方法
const goHome = () => {
  router.push('/')
}

const goBack = () => {
  if (window.history.length > 1) {
    router.go(-1)
  } else {
    router.push('/')
  }
}

const contactSupport = () => {
  router.push('/service')
}

const performSearch = () => {
  if (!searchQuery.value.trim()) {
    ElMessage.warning('请输入搜索关键词')
    return
  }
  
  // 模拟搜索功能
  ElMessage.info(`正在搜索：${searchQuery.value}`)
  // 这里可以跳转到搜索结果页面或执行实际搜索
  router.push(`/?search=${encodeURIComponent(searchQuery.value)}`)
}

const navigateTo = (path: string) => {
  router.push(path)
}

const reportError = () => {
  const errorInfo = {
    url: route.fullPath,
    timestamp: new Date().toISOString(),
    userAgent: navigator.userAgent
  }
  
  // 模拟错误报告
  console.log('Error reported:', errorInfo)
  ElMessage.success('错误报告已提交，感谢您的反馈！')
}

const viewFAQ = () => {
  router.push('/service#faq')
}

// 生成星星样式
const getStarStyle = (index: number) => {
  const size = Math.random() * 3 + 1
  const left = Math.random() * 100
  const top = Math.random() * 100
  const delay = Math.random() * 3
  
  return {
    width: `${size}px`,
    height: `${size}px`,
    left: `${left}%`,
    top: `${top}%`,
    animationDelay: `${delay}s`
  }
}

// 页面加载时的动画
onMounted(() => {
  // 记录404错误到分析系统
  console.log('404 Error:', {
    path: route.fullPath,
    referrer: document.referrer,
    timestamp: new Date().toISOString()
  })
})
</script>

<style scoped>
.not-found-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  position: relative;
  z-index: 2;
}

.not-found-content {
  text-align: center;
  color: white;
}

/* 404图标和插图 */
.error-icon {
  margin-bottom: 3rem;
  position: relative;
}

.number-404 {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.number {
  font-size: 8rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: bounce 2s infinite;
}

.number.zero {
  position: relative;
  animation-delay: 0.2s;
}

.number:nth-child(3) {
  animation-delay: 0.4s;
}

.error-illustration {
  position: relative;
  width: 300px;
  height: 200px;
  margin: 0 auto;
}

/* 星球 */
.planet {
  position: absolute;
  width: 80px;
  height: 80px;
  background: #8b5cf6;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  animation: rotate 20s linear infinite;
}

.crater {
  position: absolute;
  background: #7c3aed;
  border-radius: 50%;
}

.crater-1 {
  width: 12px;
  height: 12px;
  top: 15px;
  left: 20px;
}

.crater-2 {
  width: 8px;
  height: 8px;
  top: 35px;
  right: 15px;
}

.crater-3 {
  width: 6px;
  height: 6px;
  bottom: 20px;
  left: 30px;
}

/* 宇航员 */
.astronaut {
  position: absolute;
  left: 60%;
  top: 30%;
  animation: float 3s ease-in-out infinite;
}

.helmet {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  position: relative;
  margin-bottom: 5px;
}

.helmet::before {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  background: rgba(102, 126, 234, 0.3);
  border-radius: 50%;
  top: 5px;
  left: 5px;
}

.body {
  width: 35px;
  height: 45px;
  background: #e5e7eb;
  border-radius: 10px;
  position: relative;
  margin: 0 auto;
}

.arm {
  position: absolute;
  width: 8px;
  height: 25px;
  background: #e5e7eb;
  border-radius: 4px;
  top: 45px;
}

.arm-left {
  left: -8px;
  transform: rotate(-20deg);
}

.arm-right {
  right: -8px;
  transform: rotate(20deg);
}

.leg {
  position: absolute;
  width: 10px;
  height: 20px;
  background: #e5e7eb;
  border-radius: 5px;
  top: 85px;
}

.leg-left {
  left: 8px;
}

.leg-right {
  right: 8px;
}

/* 星星 */
.stars {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.star {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: twinkle 2s infinite;
}

/* 错误信息 */
.error-info {
  margin-bottom: 3rem;
}

.error-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: white;
}

.error-description {
  font-size: 1.2rem;
  line-height: 1.6;
  opacity: 0.9;
  max-width: 600px;
  margin: 0 auto;
}

/* 操作按钮 */
.error-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 4rem;
  flex-wrap: wrap;
}

/* 搜索建议 */
.search-suggestion {
  margin-bottom: 4rem;
}

.suggestion-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: white;
}

.search-box {
  max-width: 500px;
  margin: 0 auto;
}

/* 热门链接 */
.popular-links {
  margin-bottom: 4rem;
}

.links-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 2rem;
  color: white;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.link-item {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.link-item:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.link-icon {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  flex-shrink: 0;
}

.link-content {
  text-align: left;
}

.link-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: white;
}

.link-description {
  font-size: 0.9rem;
  opacity: 0.8;
  color: white;
  margin: 0;
}

/* 帮助信息 */
.help-info {
  max-width: 600px;
  margin: 0 auto;
}

.help-card {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 2rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.help-icon {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  flex-shrink: 0;
}

.help-content {
  text-align: left;
}

.help-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.8rem;
  color: white;
}

.help-description {
  opacity: 0.9;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  color: white;
}

.help-actions {
  display: flex;
  gap: 1rem;
}

/* 背景动画 */
.background-animation {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 1;
}

.floating-shapes {
  position: relative;
  width: 100%;
  height: 100%;
}

.shape {
  position: absolute;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  animation: float-shapes 20s infinite linear;
}

.shape-1 {
  width: 80px;
  height: 80px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.shape-2 {
  width: 60px;
  height: 60px;
  top: 20%;
  right: 15%;
  animation-delay: -5s;
}

.shape-3 {
  width: 40px;
  height: 40px;
  bottom: 30%;
  left: 20%;
  animation-delay: -10s;
}

.shape-4 {
  width: 100px;
  height: 100px;
  bottom: 10%;
  right: 10%;
  animation-delay: -15s;
}

.shape-5 {
  width: 50px;
  height: 50px;
  top: 50%;
  left: 5%;
  animation-delay: -8s;
}

/* 动画 */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes rotate {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
}

@keyframes twinkle {
  0%, 100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

@keyframes float-shapes {
  0% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
  }
  100% {
    transform: translateY(0px) rotate(360deg);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .number {
    font-size: 5rem;
  }

  .error-title {
    font-size: 2rem;
  }

  .error-description {
    font-size: 1rem;
  }

  .error-actions {
    flex-direction: column;
    align-items: center;
  }

  .links-grid {
    grid-template-columns: 1fr;
  }

  .link-item {
    flex-direction: column;
    text-align: center;
  }

  .help-card {
    flex-direction: column;
    text-align: center;
  }

  .help-actions {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 1rem;
  }

  .number {
    font-size: 4rem;
  }

  .error-illustration {
    width: 200px;
    height: 150px;
  }

  .planet {
    width: 60px;
    height: 60px;
  }

  .help-actions {
    flex-direction: column;
    align-items: center;
  }
}
</style>